const { firstLetterToUpperCase } = require('../../util/core');

module.exports = ({ Router, logger }) => {
    const router = new Router();

    router.prefix('/web/:modelName');

    router.param('modelName', async (modelName, ctx, next) => {
        modelName = firstLetterToUpperCase(modelName);
        ctx.modelName = modelName;
        console.log(ctx.user);
        await next();
    })

    const webRoutes = require('require-all')({dirname: __dirname});
    delete webRoutes.index;
    Object.values(webRoutes).forEach(route => route({ router, logger }));

    return router;
}